package hanjia;

import java.util.Arrays;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/12-下午4:13
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode108 {
    public TreeNode sortedArrayToBST(int[] nums) {

        if (nums.length==0){
            return null;
        }
        if (nums.length==1){
            return new TreeNode(nums[0]);
        }

        int mid = nums.length / 2;
        TreeNode treeNode = new TreeNode(nums[mid]);
        int[] left = Arrays.copyOfRange(nums, 0, mid);
        int[] right = Arrays.copyOfRange(nums, mid + 1, nums.length);


        treeNode.left = sortedArrayToBST(left);
        treeNode.right = sortedArrayToBST(right);
        return treeNode;


    }
}
